# -*- coding: utf-8 -*-
import pymssql

# 数据库连接信息
DB_CONFIG = {
    'server': '(local)',
    'user': 'sa',
    'password': '123456789',
    'database': 'JCDGXT',
    'charset': 'utf8'
}

# 初始化数据库连接
def get_db_connection():
    return pymssql.connect(
        server=DB_CONFIG['server'],
        user=DB_CONFIG['user'],
        password=DB_CONFIG['password'],
        database=DB_CONFIG['database'],
        charset=DB_CONFIG['charset']
    )

# 获取所有书商信息
def all():
    conn = get_db_connection()
    cursor = conn.cursor(as_dict=True)
    cursor.execute('SELECT aid, aname, apwd FROM [administrators$]')
    result = cursor.fetchall()
    conn.close()

def check_credentials(username, password):
    conn = get_db_connection()
    cursor = conn.cursor()
    cursor.execute('SELECT 1 FROM [administrators$] WHERE aid = %s AND apwd = %s', (username, password))
    result = cursor.fetchone()
    conn.close()
    return result is not None